#############
#Composite

library(foreign)
library(lattice)
library(extrafont)
library(readstata13)
library(scales)
#library(sm)
loadfonts()
datadem<-read.dta13("MarginalMatrix_Dem_Composite95CI_DYDX.dta")
datarep<-read.dta13("MarginalMatrix_Rep_Composite95CI_DYDX.dta")
datademmean<-read.dta13("MarginalMatrix_Dem_CompositeMeans_DYDX.dta")
datarepmean<-read.dta13("MarginalMatrix_Rep_CompositeMeans_DYDX.dta")

Scale<-datadem[,1]
DemCompLB<-datadem[,2]
DemCompUB<-datadem[,3]
RepCompLB<-datarep[,2]
RepCompUB<-datarep[,3]
DemCompMeans<-datademmean[,2]
RepCompMeans<-datarepmean[,2]

pdf(file="Figure3.pdf", family="Bookman")
plot(0, 1, type="n", xlim=c(0,1), ylim=c(-.15, .15), xlab="Moderator: Perceived Obstructiveness", ylab="Marginal Effect of Gender on Composite Score of Qualities")
title(main="Composite of Qualities")
box() 

polygon(c(Scale, rev(Scale)), c(DemCompLB, rev(DemCompUB)), col="gray72", border=NA)

points(Scale, DemCompMeans, type="l")

polygon(c(Scale, rev(Scale)), c(RepCompLB, rev(RepCompUB)), density=20, angle=45, col="black")

points(Scale, RepCompMeans, type="l")

abline(0, 0, col="black", lty=2, lwd=2)

legend("bottomright", cex=.98, legend=c('Democrats', 'Republicans'), fill=c("gray72", "black"), density=c(NA, 30), angle=c(NA, 45), border=c(NA, "black"))

dev.off()
